﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectPenguin.Cards;
using NSGeo.Geometry;
using ProjectPenguin.Cards.ProcessorCardHelpers;
using ProjectPenguin.UI.Dialogs;

namespace ProjectSnake
{
    public class PolylineToRectangleCard : ProcessorCardBase
    {
        public PolylineToRectangleCard() : base("多段线2矩形", "多段线2矩形", "多段线2矩形", "GamerDeck", "几何运算") { }
        static Guid _guid = Guid.Parse("{C0ED7EF9-B280-4358-A52C-86E2C0F836BF}");
        public override Guid CardGuid => _guid;

        protected override void AddInputSideDataCards(IDataCardEmbedmentHelper helper)
        {
            helper.AddWellKnownTypeOfDataCard(typeof(PolylineCurve), "多段线", "多段线", "多段线", ProjectPenguin.Cards.Enums.DataProcessingMode.OneByOne);
        }

        protected override void AddOutputSideDataCards(IDataCardEmbedmentHelper helper)
        {
            helper.AddWellKnownTypeOfDataCard(typeof(Rectangle3d), "矩形", "矩形", "矩形", ProjectPenguin.Cards.Enums.DataProcessingMode.OneByOne);
        }

        public override void Build(IDataDelivery idd)
        {
            PolylineCurve plc = new PolylineCurve();
            if (!idd.GetDataItem(0, ref plc)|| plc==null) return;

            plc.TryGetPolyline(out var pl);
            // 折中方式
            var bb = pl.BoundingBox;
            idd.SetDataItem(0, new Rectangle3d(new Plane(bb.Min, Vector3d.ZAxis), bb.Min, bb.Max));
        }
    }
}
